package cn.flying.cloud.system.param.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.system.param.entity.SysParamInfo;
import cn.flying.cloud.system.param.service.SysParamInfoService;

/**
 * 系统参数信息表 前端控制器
 *
 * @author: admin
 * @date: 2025-04-16 23:22:57
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/param")
public class SysParamInfoController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysParamInfoService sysParamInfoService;

    /**
     * 分页查询系统参数信息表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse<SysParamInfo> page(@RequestBody PageRequest<SysParamInfo> request) {
        return sysParamInfoService.getPageList(request);
    }

    /**
     * 列表查询系统参数信息表数据
     *
     * @param sysParamInfo
     * @return
     */
    @PostMapping("list")
    public Rt<?> list(@RequestBody SysParamInfo sysParamInfo) {
        List<SysParamInfo> list = sysParamInfoService.getList(sysParamInfo);
        return Rt.success(list);
    }

    /**
     * 查询系统参数信息表详情数据
     *
     * @param sysParamInfo
     * @return
     */
    @PostMapping("detail")
    public Rt<?> detail(SysParamInfo sysParamInfo) {
        return Rt.success(sysParamInfoService.getOneObj(sysParamInfo));
    }

    /**
     * 根据主键ID查询系统参数信息表详情数据
     *
     * @param id 主键ID
     * @return
     */
    @PostMapping("getById")
    public Rt<?> getById(Long id) {
        SysParamInfo sysParamInfo = sysParamInfoService.getById(id);
        return Rt.success(sysParamInfo);
    }

    /**
     * 保存系统参数信息表数据
     *
     * @param sysParamInfo
     * @return
     */
    @PostMapping("save")
    public Rt<?> save(@RequestBody SysParamInfo sysParamInfo) {
        if (Objects.isNull(sysParamInfo.getId())) {
            // 新增
            sysParamInfoService.createObj(sysParamInfo);
        } else {
            // 更新
            sysParamInfoService.updateObj(sysParamInfo);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除系统参数信息表数据
     *
     * @param sysParamInfo
     * @return
     */
    @PostMapping("delete")
    public Rt<?> delete(SysParamInfo sysParamInfo) {
        sysParamInfoService.deleteObj(sysParamInfo);
        return Rt.success("删除成功！");
    }

    /**
     * 根据主键ID删除系统参数信息表数据
     *
     * @param id 主键ID
     * @return
     */
    @GetMapping("deleteById/{id}")
    public Rt<?> deleteById(@PathVariable("id") Long id) {
        sysParamInfoService.deleteById(id);
        return Rt.success("删除成功！");
    }
}
